package api

import (
	"github.com/gin-gonic/gin"
	"go-cloud-disk/common"
	"go-cloud-disk/internal/middleware"
	"go-cloud-disk/internal/service/user"
)

func InitUserRouter(g *gin.RouterGroup) {
	user := g.Group("/user")

	// 用户登录
	user.POST("/session", middleware.CaptchaRequired("login_captcha"), UserLogin)
	// 获取用户头像
	user.GET("avatar/:id/:size", middleware.HashID(common.UserID), GetUserAvatar)
	// 获取用户主页展示用分享
	user.GET("profile/:id", middleware.HashID(common.UserID), GetUserShare)
	// 通过邮件里的链接重设密码
	user.PATCH("reset", UserReset)
}

func UserLogin(c *gin.Context) {

}

// 获取用户头像
func GetUserAvatar(c *gin.Context) {
	user.GetUserAvatar(c)
}

// 查看给定用户的分享
func GetUserShare(c *gin.Context) {
	user.GetUserShare(c)
}

// UserReset 重设密码
func UserReset(c *gin.Context) {
	var service UserResetService
	if err := c.ShouldBindJSON(&service); err == nil {
		res := user.Reset(service)
		c.JSON(200, res)
	} else {
		c.JSON(200, common.ErrorResponse(err))
	}
}
